<?php

if (!defined('BASEPATH')) exit('No direct access allowed.');

class Base_Controller extends CI_Controller
{
	//public $directory; //目录名
	//public $class; //类名
	//public $method; //方法名
	public $timestamp; //时间戳

	public $data = array(); //存放数据，用于传递给视图

	public function __construct()
	{
		parent::__construct();

		//header("Content-Type: text/html;charset=UTF-8");

		//$this->directory = $this->router->fetch_directory();
		//$this->class = $this->router->fetch_class();
		//$this->method = $this->router->fetch_method();
		$this->timestamp = time();

		$this->output->enable_profiler(TRUE);
	}
}

/**
 * 前台父控制器
 * 前台的所有控制器都需要继承这个类，它不包含验证
 */
class Front_Controller extends Base_Controller
{
	public $uid;
	public $user = array();

	public function __construct()
	{
		parent::__construct();
		$this->uid = $this->session->userdata('uid');

		if (logged_in())
		{
			//载入权限认证类
			$this->load->library('auth');
			$this->user = $this->user_model->get($this->uid);
		}
	}
}

/**
 * 控制面板父控制器
 *
 *
 */
class Manage_Controller extends Base_Controller
{
	public $uid; //int
	public $user; //array
	public $broker; //array
    public $agency; //array

	public function __construct()
	{
		parent::__construct();

		$this->uid = $this->session->userdata('uid');

		if (!logged_in())
		{
			//$url = $this->router->fetch_directory() . $this->router->fetch_class() . '/' . $this->router->fetch_method();
			redirect('user/login?ref=' . $this->uri->uri_string());
		}

		//var_dump($this->broker);exit;

		$this->_get_user_data($this->uid);
		$this->_get_broker_data($this->uid);
	}

	/**
	 * 获取用户资料
	 * 用户每日、每周、每月发帖数重置
	 */
	private function _get_user_data($uid)
	{
		$this->load->model('user_model');
		$this->user = $this->user_model->get_user_and_data($this->uid);
		$this->data['user'] = $this->user; //返回到视图
	}


	/**
	 * 获取经纪人资料
	 */
	private function _get_broker_data($uid)
	{
		//if (!$this->user['ifbroker']) return;
		$this->load->model('user_broker_model', 'broker_model');
		$this->broker = $this->broker_model->get($uid);
		$this->data['broker'] = $this->broker; //返回到视图
	}

}

/**
 * 后台父控制器
 * 后台的所有控制器都需要继承这个类，主要包含验证
 */
class Admin_Controller extends Base_Controller
{
	public function __construct()
	{
		parent::__construct();
	}
}

/* End of file MY_Controller.php */
/* Location: ./application/libraries/MY_Controller.php */
